package com.augurit.smartform.web.parser;

import org.springframework.beans.factory.annotation.Autowired;

import com.augurit.common.base.action.ExtCrudActionSupport;
import com.augurit.common.system.service.org.IAcModuleService;
import com.augurit.common.system.web.org.form.AcModuleForm;
import com.augurit.smartform.service.IPageMgmtService;
import com.augurit.smartform.service.ISmartPageDirService;
import com.augurit.smartform.web.parser.form.SmPageDirForm;

public class PageDirAction extends ExtCrudActionSupport<SmPageDirForm>{
	@Autowired
	private ISmartPageDirService pageDirService;
	@Autowired
	private IPageMgmtService pageMgmtService;
	
	// 属性
	private SmPageDirForm form;
	private Long id;
	private Long pageId;
	private Long dirId;
	private Long parentDirId;

	public Long getParentDirId() {
		return parentDirId;
	}

	public void setParentDirId(Long parentDirId) {
		this.parentDirId = parentDirId;
	}

	public Long getDirId() {
		return dirId;
	}

	public void setDirId(Long dirId) {
		this.dirId = dirId;
	}

	public Long getPageId() {
		return pageId;
	}

	public void setPageId(Long pageId) {
		this.pageId = pageId;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Override
	public String delete() throws Exception {
		pageDirService.deleteDirId(dirId);
		return null;
	}

	@Override
	public String list() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
	
	/**
	 * 更新SmPage的目录字段
	 */
	public void updatePageByDirID(){
		pageMgmtService.updateDirId(pageId, dirId);
	}
	
	/**
	 * 更新SmPageDir的父目录字段
	 */
	public void updateDirByParentDirId(){
		pageDirService.updateParentDirId(dirId, parentDirId);
	}
	
	/**
	 * 新增或编辑模块页面
	 */
	@Override
	public String input() throws Exception {
		this.extRenderFormJson(form);
		return null;
	}
	
	@Override
	protected void prepareModel() throws Exception {
		// TODO Auto-generated method stub
		if(id != null){
			form = pageDirService.get(id);
			if(form.getParentId()!=null){
				SmPageDirForm parentForm=pageDirService.get(form.getParentId());
				form.setParentName(parentForm.getName());
			}
		}else{
			form = new SmPageDirForm();
		}
	}

	@Override
	public String save() throws Exception {
		// TODO Auto-generated method stub
		pageDirService.save(form);
		this.extRenderSuccess();
		return null;
	}

	public SmPageDirForm getModel() {
		return form;
	}
}
